/* ============================================================
   BASE.CSS — CSS Reset + Global Defaults
   Always loaded after tokens.css.
   Never contains raw colour/font values — tokens only.
   ============================================================ */

/* ── Box model reset ─────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── HTML defaults ───────────────────────────────────────── */
html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  hanging-punctuation: first last;
  scroll-padding-top: var(--space-20); /* clears sticky nav on anchor jump */
}

/* ── Body ────────────────────────────────────────────────── */
body {
  min-height: 100dvh;
  line-height: 1.65;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  /* Smooth theme switching — background and text cross-fade */
  transition:
    background-color var(--transition-slow),
    color var(--transition-slow);
}

/* ── Media ───────────────────────────────────────────────── */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ── Typography ──────────────────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  text-wrap: balance;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

p,
li,
figcaption {
  text-wrap: pretty;
  max-width: 72ch; /* optimal reading line length */
}

a {
  color: inherit;
  text-decoration: none;
}

/* Reinforce link affordance for content/action links. */
.project-link,
.contact-link {
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
  text-decoration-color: color-mix(in oklch, currentColor 45%, transparent);
}

.project-link:hover,
.contact-link:hover {
  text-decoration-color: currentColor;
}

/* ── Form elements ───────────────────────────────────────── */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

/* ── Misc ────────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
}
ul[role="list"],
ol[role="list"] {
  list-style: none;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-code);
  font-size: 0.875em;
}

/* ── Selection ───────────────────────────────────────────── */
::selection {
  background: oklch(from var(--color-primary) l c h / 0.2);
  color: var(--color-text);
}

/* ── Focus ring ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Interactive baseline transitions ────────────────────── */
a,
button,
[role="button"],
input,
textarea,
select {
  transition:
    color var(--transition-interactive),
    background-color var(--transition-interactive),
    border-color var(--transition-interactive),
    box-shadow var(--transition-interactive),
    opacity var(--transition-interactive);
}

/* ── Accessibility ───────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip to content — first focusable element on the page */
.skip-link {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  padding: var(--space-2) var(--space-5);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  z-index: var(--z-nav);
  transform: translateY(-200%);
  transition: transform var(--transition-fast);
}
.skip-link:focus {
  transform: translateY(0);
}

/* ── Scroll progress bar ─────────────────────────────────────
   Uses CSS Scroll Timeline API — zero JavaScript.
   Falls back gracefully in unsupported browsers (bar simply
   won't appear, no layout impact).                          */
@supports (animation-timeline: scroll()) {
  .scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--color-primary);
    transform-origin: left center;
    transform: scaleX(0);
    z-index: var(--z-nav);
    animation: scroll-track linear both;
    animation-timeline: scroll(root block);
  }

  @keyframes scroll-track {
    from {
      transform: scaleX(0);
    }
    to {
      transform: scaleX(1);
    }
  }
}

/* ── CSS-native scroll reveal ────────────────────────────────
   .reveal class: elements animate in as they enter viewport.
   Uses CSS animation-timeline: view() — no JS, no CLS risk.
   Fallback: elements stay visible if API unsupported.       */
.reveal {
  opacity: 1; /* safe fallback */
}

@supports (animation-timeline: view()) {
  .reveal {
    opacity: 0;
    animation: reveal-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 55%;
  }

  @keyframes reveal-up {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* Staggered reveal for child elements */
.reveal-group > * {
  opacity: 1;
}

@supports (animation-timeline: view()) {
  .reveal-group {
    animation: reveal-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 50%;
  }

  .reveal-group > *:nth-child(1) {
    animation-delay: 0ms;
  }
  .reveal-group > *:nth-child(2) {
    animation-delay: 60ms;
  }
  .reveal-group > *:nth-child(3) {
    animation-delay: 120ms;
  }
  .reveal-group > *:nth-child(4) {
    animation-delay: 180ms;
  }
  .reveal-group > *:nth-child(5) {
    animation-delay: 240ms;
  }
  .reveal-group > *:nth-child(6) {
    animation-delay: 300ms;
  }
}
